#ifndef _BLOCK_H
#define _BLOCK_H

#include <device/blkio.h>
#include <device/device.h>

#define PARTITION_NAME_SIZE 20
#define DEV_ID_SIZE 20

typedef struct block_device {
    lnode_t list;
    lnode_t parts;
    blkio_ctx_t* blkio;
    device_t* dev;
    char bdev_id[DEV_ID_SIZE + 1];
    char name[PARTITION_NAME_SIZE + 1];
    u64 start_lba;
    u64 end_lba;
    u32 blk_size;
    u8 part_id;

    int (*block_read)(struct block_device*, void*, u64, size_t);
    int (*block_write)(struct block_device*, void*, u64, size_t);
    void* (*block_alloc)(struct block_device*);
    void (*block_free)(struct block_device*, void*);
} blk_dev_t;

void block_init();

int block_mount(blk_dev_t* bdev);

blk_dev_t* blk_mount_part(blk_dev_t* bdev, const char* name, size_t index, u64 start_lba, u64 end_lba);

blk_dev_t* block_alloc_dev(const char* blk_id, void* driver, io_req_handler ioreq_handler);

#endif /* _BLOCK_H */